package org.jeecg.modules.kuner.curriculumvitaebase.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.checkerframework.checker.units.qual.K;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.kuner.collectionbase.service.IKrCollectionBaseService;
import org.jeecg.modules.kuner.curriculumvitaebase.entity.KrCurriculumVitaeBase;
import org.jeecg.modules.kuner.curriculumvitaebase.service.IKrCurriculumVitaeBaseService;
import org.jeecg.modules.kuner.curriculumvitaebase.vo.CurriculumVitaeDetailVO;
import org.jeecg.modules.kuner.curriculumvitaebase.vo.CurriculumVitaeVO;
import org.jeecg.modules.kuner.hirebase.service.IKrHireBaseService;
import org.jeecg.modules.kuner.hirebase.vo.KrHireDetailVO;
import org.jeecg.modules.kuner.hirebase.vo.KrHireVO;
import org.jeecg.modules.putil.KrStatic;
import org.jeecg.modules.putil.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.Arrays;

/**
 * @Description: 个人简历
 * @Author: jeecg-boot
 * @Date: 2025-02-18
 * @Version: V1.0
 */
@Api(tags = "小程序-找人相关接口")
@RestController
@RequestMapping("/api/krCurriculumVitaeBase")
@Slf4j
public class CurriculumVitaeBaseApiController extends JeecgController<KrCurriculumVitaeBase, IKrCurriculumVitaeBaseService> {
    @Resource
    private IKrCurriculumVitaeBaseService curriculumVitaeBaseService;
    @Resource
    private LoginUserUtil loginUserUtil;

    /**
     * 修改个人的简历信息
     *
     * @param curriculumVitaeBase 修改或者添加的个人简历信息
     * @return 修改结果
     */
    @PostMapping("/modifyMyCurriculum")
    @ApiOperation("修改或者添加个人简历信息")
    public Result<?> modifyMyCurriculum(@RequestBody KrCurriculumVitaeBase curriculumVitaeBase) {
        curriculumVitaeBaseService.modifyMyCurriculum(curriculumVitaeBase);
        return Result.OK("修改成功！", curriculumVitaeBase);
    }

    /**
     * 首页列表查询
     *
     * @param mixSearch  混合查询条件
     * @param money      金额
     * @param workCity   工作城市
     * @param type       类型
     * @param edu        学历
     * @param searchType 排序类型
     * @param pageNo     分页页码
     * @param pageSize   分页大小
     * @return 查询结果
     */
    @IgnoreAuth
    @GetMapping("/list")
    @ApiOperation(
            value = "首页列表查询"
    )
    public Result<IPage<CurriculumVitaeVO>> list(
            String mixSearch,
            BigDecimal money,
            String workCity,
            String type,
            Integer edu,
            @RequestParam(defaultValue = "CREATE_TIME") KrStatic.SearchType searchType,
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        IPage<CurriculumVitaeVO> page = curriculumVitaeBaseService.mixSearch(mixSearch, money, searchType, type, edu, workCity, pageNo, pageSize);
        return Result.OK("查询成功！", page);
    }

    /**
     * 查看我的简历
     *
     * @param pageNo   分页信息
     * @param pageSize 分页大小
     * @return 查询结果
     */
    @GetMapping("/myPublish")
    @ApiOperation("我的简历")
    public Result<IPage<KrCurriculumVitaeBase>> myPublish(
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        IPage<KrCurriculumVitaeBase> page = new Page<>(pageNo, pageSize);
        page = curriculumVitaeBaseService.page(page, new LambdaQueryWrapper<KrCurriculumVitaeBase>().eq(KrCurriculumVitaeBase::getPublishUser, loginUserUtil.getLoginUser().getId()));
        return Result.OK("查询成功！", page);
    }

    /**
     * 查询详情
     *
     * @param id 工作ID
     * @return 查询结果
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("简历详情")
    public Result<CurriculumVitaeDetailVO> detail(@PathVariable String id) {
        CurriculumVitaeDetailVO curriculumVitaeDetailVO = curriculumVitaeBaseService.detail(id);
        return Result.OK("查询成功", curriculumVitaeDetailVO);
    }

    /**
     * 去收藏
     *
     * @param curriculumId 被收藏的简历id
     * @return 收藏结果
     */
    @GetMapping("/doCollection/{curriculumId}")
    @ApiOperation("去收藏")
    public Result<?> doCollection(@PathVariable String curriculumId) {
        curriculumVitaeBaseService.doCollection(curriculumId);
        return Result.OK("收藏成功！");
    }

    /**
     * 去收藏
     *
     * @param curriculumId 被收藏的简历id
     * @return 收藏结果
     */
    @GetMapping("/cancelCollection/{curriculumId}")
    @ApiOperation("取消收藏")
    public Result<?> cancelCollection(@PathVariable String curriculumId) {
        curriculumVitaeBaseService.cancelCollection(curriculumId);
        return Result.OK("取消成功！");
    }
}
